package cn.edu.sdjzu.xg23.kcsj01_backend.service.impl;

import cn.edu.sdjzu.xg23.kcsj01_backend.entity.Conference;
import cn.edu.sdjzu.xg23.kcsj01_backend.mapper.ConferenceMapper;
import cn.edu.sdjzu.xg23.kcsj01_backend.utils.SnowflakeIdGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConferenceServiceImpl {
    @Autowired
    private ConferenceMapper conferenceMapper;

    @Autowired
    private SnowflakeIdGenerator idGenerator;

    public boolean save(Conference conference) {
        long snowflakeId = idGenerator.generateId();
        conference.setId(snowflakeId);
        return conferenceMapper.save(conference);
    }

    public boolean delete(Long conferenceId) {
        return conferenceMapper.delete(conferenceId);
    }

    public boolean update(Conference conference) {
        return conferenceMapper.update(conference);
    }

    public PageInfo<Conference> get(int pageNum, int pageSize, Conference conference) {
        PageHelper.startPage(pageNum, pageSize);
        List<Conference> conferencesList = conferenceMapper.get(conference);
        return PageInfo.of(conferencesList);
    }
}